package com.tanhua.server.controller;

import com.tanhua.server.service.TestSoulService;
import com.tanhua.server.vo.AnswersList;
import com.tanhua.server.vo.ReportResultVo;
import com.tanhua.server.vo.Soul1Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("testSoul")
@Slf4j
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;

    @GetMapping("report/{id}")
    public ResponseEntity<ReportResultVo> TestResult(@PathVariable("id") Long id) {
        try {
            ReportResultVo reportResultVo = this.testSoulService.testResult(id);
            return ResponseEntity.ok(reportResultVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping
    public ResponseEntity<List<Soul1Vo>> QuestionnaireList() {
        try {
            List<Soul1Vo> soul1Vos = testSoulService.QuestionnaireList();
            return ResponseEntity.ok(soul1Vos);
        } catch (Exception e) {
            log.error("测灵魂-问卷列表出现bug,请联系郑鑫杰处理");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @PostMapping
    public ResponseEntity<String> submitQuestionnaire(@RequestBody AnswersList answersList){
        try {
            String reportId = this.testSoulService.submitQuestionnaire(answersList.getAnswers());
            if(null!=reportId){
                return ResponseEntity.ok(reportId);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}


